﻿@page
@using Volo.Abp.Account.Web.Pages
@using Volo.Abp.Account.Web.Pages.Account
@model ConsentModel
<abp-card id="IdentityServerConsentWrapper">
    <abp-card-header>
        <div class="row">
            <div class="col-md-12">
                <h2>
                    @if (Model.ClientInfo.ClientLogoUrl != null)
                    {
                        <img src="@Model.ClientInfo.ClientLogoUrl">
                    }

                    @Model.ClientInfo.ClientName
                    <small>is requesting your permission</small>
                </h2>
            </div>
        </div>
    </abp-card-header>
    <abp-card-body>
        <form method="post" asp-page="/Consent">
            <input type="hidden" asp-for="ReturnUrl" />
            <input type="hidden" asp-for="ReturnUrlHash" />

            <div>Uncheck the permissions you do not wish to grant.</div>

            @if (Model.ConsentInput.IdentityScopes.Any())
            {
                <h3>Personal Information</h3>

                <ul class="list-group">
                    @for (var i = 0; i < Model.ConsentInput.IdentityScopes.Count; i++)
                    {
                        <li class="list-group-item">
                            <div class="form-check">
                                <label asp-for="@Model.ConsentInput.IdentityScopes[i].Checked" class="form-check-label">
                                    <input asp-for="@Model.ConsentInput.IdentityScopes[i].Checked" class="form-check-input"  />
                                    @Model.ConsentInput.IdentityScopes[i].DisplayName
                                    @if (Model.ConsentInput.IdentityScopes[i].Required)
                                    {
                                        <span><em>(required)</em></span>
                                    }
                                </label>
                            </div>
                            <input asp-for="@Model.ConsentInput.IdentityScopes[i].Name" type="hidden" /> @* TODO: Use attributes on the view model instead of using hidden here *@
                            @if (Model.ConsentInput.IdentityScopes[i].Description != null)
                            {
                                <div class="consent-description">
                                    @Model.ConsentInput.IdentityScopes[i].Description
                                </div>
                            }
                        </li>
                    }
                </ul>
            }

            @if (Model.ConsentInput.ApiScopes.Any())
            {
                <h3>Application Access</h3>

                <ul class="list-group">
                    @for (var i = 0; i < Model.ConsentInput.ApiScopes.Count; i++)
                    {
                        <li class="list-group-item">
                            <div class="form-check">
                                <label asp-for="@Model.ConsentInput.ApiScopes[i].Checked" class="form-check-label">
                                    <input asp-for="@Model.ConsentInput.ApiScopes[i].Checked" class="form-check-input" disabled="@Model.ConsentInput.ApiScopes[i].Required" />
                                    @Model.ConsentInput.ApiScopes[i].DisplayName
                                    @if (Model.ConsentInput.ApiScopes[i].Required)
                                    {
                                        <span><em>(required)</em></span>
                                    }
                                </label>
                            </div>
                            <input asp-for="@Model.ConsentInput.ApiScopes[i].Name" type="hidden" /> @* TODO: Use attributes on the view model instead of using hidden here *@
                            @if (Model.ConsentInput.ApiScopes[i].Description != null)
                            {
                                <div class="consent-description">
                                    @Model.ConsentInput.ApiScopes[i].Description
                                </div>
                            }
                        </li>
                    }
                </ul>
            }

            @if (Model.ClientInfo.AllowRememberConsent)
            {
                <div class="form-check">
                    <label asp-for="@Model.ConsentInput.RememberConsent" class="form-check-label">
                        <input asp-for="@Model.ConsentInput.RememberConsent" class="form-check-input" />
                        <strong>Remember My Decision</strong>
                    </label>
                </div>
            }

            <div>
                <button name="UserDecision" value="yes" class="btn btn-primary" autofocus>Yes, Allow</button>
                <button name="UserDecision" value="no" class="btn">No, Do Not Allow</button>
                @if (Model.ClientInfo.ClientUrl != null)
                {
                    <a class="pull-right btn btn-secondary" target="_blank" href="@Model.ClientInfo.ClientUrl">
                        <strong>@Model.ClientInfo.ClientName</strong>
                    </a>
                }
            </div>

            <div asp-validation-summary="All" class="text-danger"></div>

        </form>
    </abp-card-body>
</abp-card>